package com.hanhanxiaochong.zhongxiangchuanmei.view.home.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hanhanxiaochong.zhongxiangchuanmei.R;
import com.hanhanxiaochong.zhongxiangchuanmei.bean.ProjectEvaluationListBean;
import com.hanhanxiaochong.zhongxiangchuanmei.config.ItemViewDelegate;
import com.hanhanxiaochong.zhongxiangchuanmei.config.MultiItemTypeAdapter;
import com.hanhanxiaochong.zhongxiangchuanmei.config.ViewHolder;
import com.hanhanxiaochong.zhongxiangchuanmei.util.glide.GlideImgManager;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.RetrofitSource;

import java.util.List;

/**
 * Created by rockphoenix on 2018/7/16.
 */

public class EvaluationListAdapter extends MultiItemTypeAdapter<ProjectEvaluationListBean.ListBean> {

    public EvaluationListAdapter(Context context, List<ProjectEvaluationListBean.ListBean> datas) {
        super(context, datas);
        addItemViewDelegate(new EvaluationHeaderDelegate());
    }

    class EvaluationHeaderDelegate implements ItemViewDelegate<ProjectEvaluationListBean.ListBean> {

        @Override
        public int getItemViewLayoutId() {
            return R.layout.item_evaluation;
        }

        @Override
        public boolean isForViewType(ProjectEvaluationListBean.ListBean item, int position) {
            return true;
        }

        @Override
        public void convert(ViewHolder holder, ProjectEvaluationListBean.ListBean bean, int position) {
            ImageView avatar = holder.getView(R.id.iv_avatar);
            GlideImgManager.glideLoader(mContext, RetrofitSource.image_url + bean.getAvatar(), R.mipmap.img_error, R.mipmap.img_error, avatar);
            holder.setText(R.id.tv_name, bean.getUser_login());
            holder.setText(R.id.tv_time, bean.getAdd_time());
            holder.setText(R.id.tv_evaluation_content, bean.getContent());
            StringBuilder tag = new StringBuilder();
            for (int i = 0; i < bean.getNotes().size(); i++) {
                ProjectEvaluationListBean.ListBean.NotesBean notesBean = bean.getNotes().get(i);
                tag.append(notesBean.getN_title());
                if (i != bean.getNotes().size() - 1) {
                    tag.append(",");
                }
            }
            holder.setText(R.id.tv_evaluation_tag, tag.toString());
            ImageView ivEvaluation = holder.getView(R.id.iv_evaluate);
            if (bean.getPic() != null) {
                GlideImgManager.glideLoader(mContext, RetrofitSource.image_url + bean.getPic(), R.mipmap.img_error, R.mipmap.img_error, ivEvaluation);
            } else {
                ivEvaluation.setVisibility(View.GONE);
            }
            TextView reply = holder.getView(R.id.tv_shop_reply);
            if (bean.getA_con() != null) {
                reply.setText("商家回应：" + bean.getA_con());
            } else {
                reply.setVisibility(View.GONE);
            }
        }
    }

}
